package com.college.controller.resource;


import com.college.common.pojo.ao.CampusInformation;
import com.college.common.pojo.dto.resource.AddCampusInformationDTO;
import com.college.common.pojo.dto.resource.QueryCampusInformationDTO;
import com.college.common.pojo.dto.resource.UpdateCampusInformationDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.service.CampusInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 校园资讯 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/campus-information")
@Api(tags = "校园资讯")
@Slf4j
public class CampusInformationController {

    @Autowired
    private CampusInformationService campusInformationService;

    @ApiOperation(value = "查询校园资讯列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<CampusInformation>> queryList(QueryCampusInformationDTO queryCampusInformationDTO) {
        return CommonResult.success(campusInformationService.queryList(queryCampusInformationDTO));
    }

    @ApiOperation(value = "查询校园资讯列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<CampusInformation>> queryListPage(QueryCampusInformationDTO queryCampusInformationDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(campusInformationService.queryListPage(queryCampusInformationDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增校园资讯")
    @PostMapping(value = "/add")
    public CommonResult<String> addCampusInformation(@RequestBody AddCampusInformationDTO addCampusInformationDTO) {
        return campusInformationService.addCampusInformation(addCampusInformationDTO);
    }

    @ApiOperation(value = "删除校园资讯")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteCampusInformation(@PathVariable Long id) {
        return CommonResult.success(campusInformationService.removeById(id));
    }

    @ApiOperation(value = "批量删除校园资讯")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteCampusInformation(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(campusInformationService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新校园资讯")
    @PutMapping(value = "/update")
    public CommonResult<String> updateCampusInformation(@RequestBody UpdateCampusInformationDTO updateCampusInformationDTO) {
        return campusInformationService.updateCampusInformation(updateCampusInformationDTO);
    }
}

